﻿using System;
namespace AEM.Data
{
    public partial class DataLog : IDisposable
    {
        protected object lockedObj = new object();
        protected string xmlPath = string.Empty;
        
        public DataLog(string xmlPath)
            : this()
        {
            this.xmlPath = xmlPath;

            if (!System.IO.File.Exists(xmlPath))
            {
                return;
            }
            try
            {
                lock (lockedObj)
                {
                    this.ReadXml(xmlPath, System.Data.XmlReadMode.InferTypedSchema);
                }
            }
            catch (Exception ex)
            {
                try
                {
                    System.IO.File.Delete(xmlPath);
                }
                catch
                {
                    throw ex;
                }
            }
        }

        public void Save()
        {
            try
            {
                lock (lockedObj)
                {
                    this.WriteXml(xmlPath, System.Data.XmlWriteMode.IgnoreSchema);
                }
            }
            catch { }
        }

        void IDisposable.Dispose()
        {
            throw new NotImplementedException();
        }
    }
}

